package absolute_zero.com.urbox;
import android.content.Context;
import android.database.Cursor;
import android.provider.Contacts;

public class ContactLookup
{
	public static String numberToName(String number, Context context) //for context, pass 'this'. returns "" if there is no result or more than one, otherwise returns the name
	{								//requires phone number to be exact match and requires number to be digits only (no dashes or spaces)
		number = new StringBuffer(number).reverse().toString();
		Cursor result = context.getContentResolver().query(Contacts.Phones.CONTENT_URI, null, "NUMBER_KEY = \'" + number + "\'", null, null);
		if (result.getCount() == 1)
		{
			result.moveToFirst();
			return result.getString(result.getColumnIndex(Contacts.PeopleColumns.NAME));
		}
		else
			return "";
	}
}
